<template>
  <view class="wrap">
    <view class="card">
      <view class="title">注册</view>

      <input v-model="form.username" class="input" placeholder="请输入用户名" />
      <input v-model="form.password" class="input" password placeholder="请输入密码" />
      <input v-model="form.confirm" class="input" password placeholder="请确认密码" />

      <button class="btn" :disabled="!canSubmit" @click="toReg">注册</button>

      <view class="link" @click="toLoginPage">已有账号？<text class="blue">去登录</text></view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      form: { username: '', password: '', confirm: '' }
    }
  },
  computed: {
    canSubmit() {
      const { username, password, confirm } = this.form
      return username && password && confirm && password === confirm
    }
  },
    methods: {
  toReg() {
    const { username, password, confirm } = this.form
    if (username.length < 3) return uni.showToast({ title: '用户名至少3位', icon: 'none' })
    if (password.length < 6) return uni.showToast({ title: '密码至少6位', icon: 'none' })
    if (password !== confirm) return uni.showToast({ title: '两次密码不一致', icon: 'none' })
  
    /* ✅ 写死钥匙，表示“已注册” */
    uni.setStorageSync('hasReg', '1')
  
    uni.showToast({ title: '注册成功', icon: 'success' })
    setTimeout(() => uni.navigateBack(), 800)
  },
      toLoginPage() {
        uni.navigateBack()
      }
    }
}
</script>


<style>
.wrap {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
}
.card {
  width: 600rpx;
  padding: 60rpx 50rpx;
  background: #fff;
  border-radius: 16rpx;
  box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.06);
}
.title {
  font-size: 40rpx;
  font-weight: 600;
  text-align: center;
  margin-bottom: 50rpx;
}
.input {
  height: 88rpx;
  padding: 0 24rpx;
  margin-bottom: 30rpx;
  border: 2rpx solid #e5e5e5;
  border-radius: 8rpx;
  font-size: 30rpx;
}
.btn {
  height: 88rpx;
  line-height: 88rpx;
  background: #2979ff;
  color: #fff;
  border-radius: 8rpx;
  font-size: 32rpx;
}
.btn[disabled] {
  background: #a8c5ff;
}
.link {
  margin-top: 30rpx;
  text-align: center;
  font-size: 28rpx;
  color: #666;
}
.blue {
  color: #2979ff;
}
</style>